package com.foodorder.config;

import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class PasswordResetService {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @Autowired
    private PasswordEncoder passwordEncoder;
    
    @PostConstruct
    public void resetAdminPassword() {
        String encodedPassword = passwordEncoder.encode("123456");
        System.out.println("重置管理员密码...");
        System.out.println("新的加密密码: " + encodedPassword);
        
        int updated = jdbcTemplate.update(
            "UPDATE admins SET password = ? WHERE username = ?",
            encodedPassword, "admin"
        );
        
        System.out.println("管理员密码重置结果: 更新了 " + updated + " 条记录");
    }
} 